﻿@{
    ViewBag.Title = "Common Command";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
        <ol class="breadcrumb">
            <li><a href="/Home.html">Home</a></li>
            <li><a href="/WebApp/WebApi"> Sanelib WebApp</a></li>  <li class="active">Pipeline</li>
        </ol>
       
            <div id="introduction">
                <h1 class="text-left">Pipeline in Windows PowerShell</h1>
            </div>
            <div id="definition">
                <p>
                    <b>First – What is a Pipeline?</b>
                </p>
                <p>-	And a simple answer is it’s a series of commands where the output of one becomes the input of the next.</p>
            </div>
            <div id="represents">
                <p>
                    A Pipeline is represented by <b>“ | “</b>.
                </p>
            </div>
            <div id="Example1">
                <b>Example-1.1</b>
                <p>Pipeline is used for the output of the before pipeline is make a input for the after the pipeline commands see in the example</p>
                <div class="divcolor">
                    <pre><code>Get-Content task.log | foreach {Write-Output $_}</code></pre>
                </div>
                <img src="~/Images/Wps/WPS_pipeline1.1.png" alt="pipeline measure-object example" width="100%" height="100%" />
                <b>Example-1.2</b>
                <img src="~/Images/Wps/WPS_pipeline1.2.png" alt="pipeline measure-object example" width="100%" height="100%" />
                <p><b>$_</b>  is a Special character. In a powershell the <b>$_</b> variable represents the current object when using specific type of loop or blocks of code</p>
                <p>-    The following table shows a list of all of the special variables available in powershell.</p>
                <table class="table table-condensed">
                    <tr>
                        <th>Variable Name</th>
                        <th>Description</th>
                    </tr>
                    <tr>
                        <td class="active">$_</td>
                        <td>The current pipeline object; used in script blocks, filters, the process clause of functions, where-object, foreach-object and switch</td>
                    </tr>
                    <tr>
                        <td class="active">$^</td>
                        <td>contains the first token of the last line input into the shell</td>
                    </tr>
                    <tr>
                        <td class="active">$$</td>
                        <td>contains the last token of last line input into the shell</td>
                    </tr>
                    <tr>
                        <td class="active">$?</td>
                        <td>Contains the success/fail status of the last statement</td>
                    </tr>
                    <tr>
                        <td class="active">$Error</td>
                        <td>If an error occurred, the object is saved in the $error PowerShell variable</td>
                    </tr>
                    <tr>
                        <td class="active">$foreach</td>
                        <td>Refers to the enumerator in a foreach loop.</td>
                    </tr>
                    <tr>
                        <td class="active">$true</td>
                        <td>Boolean TRUE</td>
                    </tr>
                    <tr>
                        <td class="active">$false</td>
                        <td>Boolean FALSE</td>
                    </tr>
                    <tr>
                        <td class="active">$null</td>
                        <td>a null object</td>
                    </tr>
                </table>
            </div>
            <div id="Example2">
                <b>Example-2</b>
                <p>
                    if you want the Filter Items in a List or Command Output then a poweshell script also provided to the <b>Where-Object</b> which is also useful to the Sorting and filtering
                </p>
                <p>-    Here, To list all running processes that have "search" in their name, use the -like operator to compare against the process's Name property:</p>
                <div class="divcolor">
                    <pre><code>Get-Process | Where-Object { $_.Name -like "*Search*" }</code></pre>
                </div>
                <img src="~/Images/Wps/WPS_pipeline2.1.png" alt="pipeline measure-object example" width="100%" height="100%" />
                <p>-    To list all directories in the current location, test the PsIsContainer property:</p>
                <div class="divcolor">
                    <pre><code>Get-ChildItem | Where-Object { $_.PsIsContainer }</code></pre>
                </div>
                <img src="~/Images/Wps/WPS_pipeline2.2.png" alt="pipeline measure-object example" width="100%" height="100%" />
                <p>-    To list all stopped services, use the -eq operator to compare against the service's Status property:</p>
                <div class="divcolor">
                    <pre><code>Get-Service | Where-Object { $_.Status -eq "Stopped" }</code></pre>
                </div>
                <img src="~/Images/Wps/WPS_pipeline2.3.png" alt="pipeline measure-object example" width="100%" height="100%" />
            </div>
            <div id="Example3">
                <b>Example-3</b>
                <p>how to count word,lines,character,etc.</p>
                <div class="divcolor">
                    <pre><code>Get-Content ‘filename’ | Measure-Object –line –word</code></pre>
                </div>
                <img src="~/Images/Wps/WPS_pipeline.png" alt="pipeline measure-object example" width="100%" height="100%" />
                <p>
                    here the powershell Measure-Object is used for the count a number of lines,word,character,number etc.
                    in the example count only the number of line and word
                </p>
                <p>An object-based pipeline opens up enormous possibilities, making system administration both immensely simpler and more powerful.</p>
            </div>
            <div id="Example4">
                <p>
                    <b>Now Let’s Perform Some Sorting and Listing with Pipeline</b>
                </p>
                <p>
                    Here the used of the Group where <b>Group</b> is a property that can be used to group data.
                </p>
                <b>OPTIONS: </b>
                <ol style="padding-left: 30px;">
                    <li>
                        <p><b>–AsHashTable [Column] : </b>It Creates an hash of the prior list with the help of pipeline.</p>
                        <p>Example-4.1</p>
                        <pre><code>Get-Process | Group –AsHashTable ID</code></pre>
                        <img src="~/Images/Wps/WPS_pipeline1.png" alt="pipeline group hashtable example" width="100%" height="100%" />
                        <p>
                            <b>NOTE: </b>Objects are more agile while working on them with different operation hence we should use “Group-Object” instead of “group”.
                        </p>
                    </li>
                    <li>
                        <p><b>–AsString : </b>It Groups and shows only the string they are assigned to. Simply Hashtable will print Class Name too. -AsString  parameter convert all of the values to their string equivalents</p>
                        <p>Example-4.2</p>
                        <pre><code>Get-Process | group –AsHashTable –AsString ID</code></pre>
                        <img src="~/Images/Wps/WPS_pipeline2.png" alt="pipeline group hashtable example" width="100%" height="100%" />
                        <p>
                            <b>NOTE: </b>Objects are more agile while working on them with different operation hence we should use “Group-Object” instead of “group”.
                        </p>
                    </li>
                </ol>
            </div>
       

